from django.db import models


# Create your models here.

class storeinfo(models.Model):
    """店铺信息表"""
    code = models.CharField(max_length=32, verbose_name="店号")
    name = models.CharField(max_length=32, verbose_name="店名")
    isopen = models.IntegerField()

    def __str__(self):
        return self.name


class userinfo(models.Model):
    """用户信息表"""
    name = models.CharField(max_length=32, verbose_name="姓名")
    password = models.CharField(max_length=32, verbose_name="密码")
    no = models.CharField(max_length=32, verbose_name="帐号")
    level_choices = (
        (0, "管理员"),
        (1, "员工")
    )
    level = models.IntegerField(choices=level_choices, verbose_name="权限")
    isty_choices = (
        (0, "已停用"),
        (1, "启用")
    )
    isty = models.IntegerField(choices=isty_choices, verbose_name="状态")
    storecode = models.ForeignKey(to="storeinfo", to_field="id", on_delete=models.CASCADE, verbose_name="所属店铺")


class skuinfo(models.Model):
    """sku信息表"""
    sku = models.CharField(max_length=32, verbose_name="款号")
    year = models.CharField(max_length=32, verbose_name="年份")
    season = models.CharField(max_length=32, verbose_name="季节")
    wave = models.CharField(max_length=32, verbose_name="波段")
    color = models.CharField(max_length=32, verbose_name="颜色")
    colorCode = models.CharField(max_length=32, verbose_name="色号")
    size = models.CharField(max_length=32, verbose_name="尺码")
    price = models.CharField(max_length=32, verbose_name="价格")
    cost = models.CharField( max_length=32, verbose_name="成本价格" )
    type = models.CharField(max_length=32, verbose_name="品类")
    brand = models.ForeignKey(to="brandlist",to_field="id", on_delete=models.CASCADE, verbose_name="所属品牌")


class RKinfo(models.Model):
    """入库信息表"""
    rkName = models.CharField(max_length=32, verbose_name="发货库名称")
    store = models.ForeignKey(to="storeinfo", to_field="id", on_delete=models.CASCADE, verbose_name="收货店铺")
    rkData = models.CharField(max_length=32, verbose_name="单据日期")
    bz = models.CharField(max_length=32, verbose_name="备注")

class RKinfoList(models.Model):
    """入库明细信息表"""
    rkinfo = models.ForeignKey(to="RKinfo", to_field="id", on_delete=models.CASCADE, verbose_name="单据编号")
    sku = models.CharField(max_length=32, verbose_name="款号")
    num = models.CharField(max_length=32, verbose_name="数量")
    cost = models.CharField( max_length=32, verbose_name="成本价格" , blank=True, null=True)


class CKinfo(models.Model):
    """出库信息表"""
    store = models.ForeignKey(to="storeinfo", to_field="id", on_delete=models.CASCADE, verbose_name="发货店铺")
    ckName = models.CharField(max_length=32, verbose_name="收货库名称")
    ckData = models.DateTimeField(verbose_name="单据时间")
    bz = models.CharField(max_length=32, verbose_name="备注")


class CKinfoList(models.Model):
    """出库明细信息表"""
    ckinfo = models.ForeignKey(to="CKinfo", to_field="id", on_delete=models.CASCADE, verbose_name="单据编号")
    sku = models.CharField(max_length=32, verbose_name="款号")
    num = models.CharField(max_length=32, verbose_name="数量")
    cost = models.CharField( max_length=32, verbose_name="成本价格", blank=True, null=True )

class DBinfo(models.Model):
    """出库信息表"""
    ckStore = models.ForeignKey(to="storeinfo", to_field="id", on_delete=models.CASCADE, verbose_name="发货店铺",
                                related_name="ckstore")
    rkStore = models.ForeignKey(to="storeinfo", to_field="id", on_delete=models.CASCADE, verbose_name="收货店铺",
                                related_name="rkstore")
    ckData = models.DateTimeField(verbose_name="单据时间")
    state_choices = (
        (0, "未收货"),
        (1, "已收货")
    )
    state = models.IntegerField(choices=state_choices, verbose_name="单据状态")
    bz = models.CharField(max_length=32, verbose_name="备注")


class DBinfoList(models.Model):
    """出库明细信息表"""
    dbinfo = models.ForeignKey(to="DBinfo", to_field="id", on_delete=models.CASCADE, verbose_name="单据编号")
    sku = models.CharField(max_length=32, verbose_name="款号")
    num = models.CharField(max_length=32, verbose_name="数量")

class PDinfo(models.Model):
    """盘点信息表"""
    pdStore = models.ForeignKey(to="storeinfo", to_field="id", on_delete=models.CASCADE, verbose_name="盘点店铺")
    pdData = models.DateTimeField(verbose_name="单据时间", auto_now=True)
    bz = models.CharField(max_length=32, verbose_name="备注", blank=True, null=True)
    state_choices = (
        (0, "已保存"),
        (1, "已确认"),
        (2, "已过帐")
    )
    state = models.IntegerField( choices=state_choices, verbose_name="单据状态" )
class PDinfoList(models.Model):
    pdInfoID = models.ForeignKey(to="PDinfo", to_field="id", on_delete=models.CASCADE, verbose_name="盘点单ID")
    sku = models.CharField( max_length=32, verbose_name="款号" )
    num = models.CharField( max_length=32, verbose_name="数量" )
    pdnum = models.CharField( max_length=32, verbose_name="盘点数量" )
    cynum = models.CharField(max_length=32, verbose_name="差异数量")


class inventory(models.Model):
    """库存明细表"""
    sku = models.CharField( max_length=32, verbose_name="款号" )
    num = models.CharField( max_length=32, verbose_name="数量" )
    storecode = models.ForeignKey( to="storeinfo", to_field="id", on_delete=models.CASCADE, verbose_name="所属店铺" )
    fhnum = models.CharField( max_length=32, verbose_name="发货数量" )
    shnum = models.CharField( max_length=32, verbose_name="收货数量" )

class sypeople(models.Model):
    """收银员信息表"""
    name = models.CharField(max_length=32, verbose_name="姓名")
    store = models.ForeignKey( to="storeinfo", to_field="id", on_delete=models.CASCADE, verbose_name="所属店铺" )

class zffslist(models.Model):
    """支付方式信息表"""
    name = models.CharField(max_length=32, verbose_name="名称")

class brandlist(models.Model):
    """品牌信息表"""
    name = models.CharField(max_length=32, verbose_name="名称")

class salelist(models.Model):
    """销售明细信息表"""
    sku = models.CharField(max_length=32, verbose_name="款号")
    num = models.IntegerField(verbose_name="数量")
    price = models.FloatField(verbose_name="单价")
    pid = models.CharField(max_length=32, verbose_name="单号")
    time = models.CharField(max_length=32, verbose_name="订单时间")
    store = models.ForeignKey(to="storeinfo", to_field="id", on_delete=models.CASCADE, verbose_name="店铺")
    syname = models.ForeignKey(to="sypeople", to_field="id", on_delete=models.CASCADE, verbose_name="收银员")
    zffs = models.ForeignKey(to="zffslist", to_field="id", on_delete=models.CASCADE, verbose_name="收银方式")
    opid = models.CharField(max_length=32, verbose_name="关联单号", blank=True, null=True)
    member = models.ForeignKey(to="member",to_field="id",on_delete=models.CASCADE, verbose_name="会员",blank=True,null=True)

class packageSaleList(models.Model):
    """套餐销售信息表"""
    package = models.CharField(max_length=32,verbose_name="套餐名")
    price = models.FloatField(verbose_name="单价")
    time = models.DateTimeField( verbose_name="操作时间", auto_now=True)
    member = models.ForeignKey(to="member",to_field="id", verbose_name="会员",on_delete=models.CASCADE)
    storecode = models.ForeignKey( to="storeinfo", to_field="id", on_delete=models.CASCADE, verbose_name="所属店铺" )
    times = models.IntegerField(verbose_name="套餐次数")


class packageInventoryList(models.Model):
    """套餐库存信息表"""
    sku = models.CharField( max_length=32, verbose_name="款号" )
    num = models.IntegerField( verbose_name="数量" )
    member = models.ForeignKey( to="member", to_field="id", verbose_name="会员", on_delete=models.CASCADE )
    storecode = models.ForeignKey( to="storeinfo", to_field="id", on_delete=models.CASCADE, verbose_name="所属店铺" )


class member(models.Model):
    """会员信息表"""
    name = models.CharField(max_length=32, verbose_name="姓名")
    phone = models.CharField(max_length=11, verbose_name="手机号")
    sex_choices = (
        (0, "男"),
        (1, "女")
    )
    sex = models.IntegerField( choices=sex_choices, verbose_name="性别" )
    points = models.IntegerField(verbose_name="会员积分")
    birthday = models.DateTimeField( verbose_name="生日" )
    time = models.DateTimeField( verbose_name="开会员时间" )

class memberOP(models.Model):
    """会员积分操作信息表"""
    name = models.CharField(max_length=32, verbose_name="姓名")
    phone = models.CharField( max_length=11, verbose_name="手机号" )
    oppoints = models.IntegerField(verbose_name="会员修改积分")
    time = models.DateTimeField( verbose_name="开会员时间",auto_now=True)

class sample(models.Model):
    """样品信息表"""
    sku = models.CharField(max_length=32, verbose_name="款号")
    num = models.IntegerField(verbose_name="数量")
    time = models.CharField(max_length=32, verbose_name="订单时间")
    store = models.ForeignKey( to="storeinfo", to_field="id", on_delete=models.CASCADE, verbose_name="店铺" )

class packagelist(models.Model):
    """套餐信息表"""
    sku = models.CharField(max_length=32, verbose_name="款号")
    num = models.IntegerField(verbose_name="数量")
    package = models.ForeignKey(to="package", to_field='id',on_delete=models.CASCADE,verbose_name='套餐ID')

class package(models.Model):
    name = models.CharField(max_length=32, verbose_name="名称")
    price = models.FloatField( verbose_name="套餐价格" )
    times = models.IntegerField(verbose_name="套餐次数")
